import com.sun.java.accessibility.util.TopLevelWindowMulticaster;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.*;
import java.util.stream.Collector;
import java.util.stream.Collectors;


/**
 * @author yu
 * @date 2025年05月14日 20:40
 */
public class Main3 {
    static class Experience{
        int id;
        long score;
        Experience(int id, long score){
            this.id = id;
            this.score = score;
        }

    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt((sc.nextLine()));
        Map<Integer, Long> pool = new HashMap<>();
        Set<Integer> extracted = new HashSet<>();
        List<String> outputs = new ArrayList<>();

        for(int i=0;i<N;i++){
            String line = sc.nextLine().trim();
            if(line.startsWith("+")){
                String [] parts = line.split("\\s+");
                int id = Integer.parseInt(parts[1]);
                long score = Long.parseLong(parts[2]);
                pool.put(id, score);
                }else if(line.startsWith("=")){
                String[] parts = line.split("\\s+");
                int id = Integer.parseInt(parts[1]);
                long newScore = Long.parseLong(parts[2]);
                if(pool.containsKey(id)){
                    pool.put(id, newScore);
                    extracted.clear();
                }
            }else if(line.startsWith("-")){
                String[] parts = line.split("\\s+");
                int k = Integer.parseInt(parts[1]);

                List<Experience> candidates = new ArrayList<>();
                for(Map.Entry<Integer, Long> entry : pool.entrySet()){
                    if(!extracted.contains(entry.getKey())){
                        candidates.add(new Experience(entry.getKey(), entry.getValue()));
                    }
                }
                if(candidates.size() < k){
                    outputs.add("-1");
                    continue;
                }

                candidates.sort((a,b) -> {
                    if(b.score != a.score){
                        return Long.compare(b.score, a.score);
                    }
                    return Integer.compare(a.id, b.id);
                });

                List<Integer> topK = new ArrayList<>();
                for(int j=0;j<k;j++){
                    topK.add(candidates.get(j).id);
                    extracted.add(candidates.get(j).id);
                }

                outputs.add(topK.stream()
                        .map(String::valueOf)
                        .collect(Collectors.joining(" ")));
            }
        }

        if(outputs.isEmpty()) {
            System.out.println("null");
        }else{
            for(String out : outputs){
                System.out.println(out);
            }
        }
    }
}
